/*
 * @Author: huangtianyang 916072572@qq.com
 * @Date: 2023-09-01 09:15:51
 * @LastEditors: huangtianyang
 * @LastEditTime: 2023-10-13 16:40:13
 * @FilePath: \cxl-admin\src\pages\index\index.ts
 */
import {
    companyProductMonthStatistics,
    companyProductSumStatistics,
    queryThisMonthStoreCompanyCount,
    registerStatistics
} from '@/apis/index'
import { reactive } from 'vue'
import icon_1 from '@/assets/images/home-icon-8.png'
import icon_2 from '@/assets/images/home-icon-6.png'
import icon_3 from '@/assets/images/home-icon-4.png'
import icon_4 from '@/assets/images/home-icon-2.png'
import icon_5 from '@/assets/images/home-icon-7.png'
import icon_6 from '@/assets/images/home-icon-1.png'
import { userStore } from '@/store/user.store'

export default class IndexData {
    list = reactive([
        {
            label: '套餐购买统计',
            className: 'setMeal',
            column: 4,
            visible: true,
            title: [
                '累计购买金额',
                '出险套餐',
                '维保套餐',
                '新能源套餐',
                '本月购买金额',
                '出险套餐',
                '出险套餐',
                '出险套餐'
            ],
            bg: ['bg1', 'bg2', 'bg2', 'bg2', 'bg3', 'bg4', 'bg4', 'bg4'],
            icon: [icon_1, icon_2, icon_3, icon_4, icon_5, icon_6, icon_6, icon_6],
            iconSize: [true, false, false, false, true, false, false, false],
            data: [0, 0, 0, 0, 0, 0, 0, 0],
            unit: '元'
        },
        {
            label: '查询统计',
            className: 'query',
            column: 6,
            visible: true,
            title: [
                '出险总查询量',
                '维保总查询量',
                '新能源总查询量',
                '（本月）出险查询量',
                '（本月）维保查询量',
                '（本月）新能源查询量'
            ],
            bg: [],
            icon: [],
            iconSize: [],
            data: [0, 0, 0, 0, 0, 0],
            unit: '次'
        },
        {
            label: '注册统计',
            className: 'register',
            column: 4,
            visible: true,
            title: ['本月注册企业', '累计注册企业', '审核通过企业', '审核不通过企业'],
            bg: [],
            icon: [],
            iconSize: [],
            data: [0, 0, 0, 0],
            unit: '家'
        }
    ])
    constructor() {
        const uStore = userStore()

        this.list[2].visible = uStore.isSuperAdmin

        companyProductMonthStatistics(Number(uStore.companyId) === 1 ? undefined : uStore.companyId).then(res => {
            if (res.data.value === 200) {
                res.data.data.forEach((item: any) => {
                    if (item.productType === 1) {
                        this.list[0].data[5] = Number(item.storeAmount)
                        this.list[1].data[3] = Number(item.searchCount)
                    } else if (item.productType === 2) {
                        this.list[0].data[6] = Number(item.storeAmount)
                        this.list[1].data[4] = Number(item.searchCount)
                    } else if (item.productType === 3) {
                        this.list[0].data[7] = Number(item.storeAmount)
                        this.list[1].data[5] = Number(item.searchCount)
                    }
                })
                this.list[0].data[4] = Number(
                    (this.list[0].data[5] + this.list[0].data[6] + this.list[0].data[7]).toFixed(2)
                )
            }
        })
        companyProductSumStatistics(Number(uStore.companyId) === 1 ? undefined : uStore.companyId).then(res => {
            if (res.data.value === 200) {
                res.data.data.forEach((item: any) => {
                    if (item.productType === 1) {
                        this.list[0].data[1] = Number(item.storeAmount)
                        this.list[1].data[0] = Number(item.searchCount)
                    } else if (item.productType === 2) {
                        this.list[0].data[2] = Number(item.storeAmount)
                        this.list[1].data[1] = Number(item.searchCount)
                    } else if (item.productType === 3) {
                        this.list[0].data[3] = Number(item.storeAmount)
                        this.list[1].data[2] = Number(item.searchCount)
                    }
                })
                this.list[0].data[0] = Number(
                    (this.list[0].data[1] + this.list[0].data[2] + this.list[0].data[3]).toFixed(2)
                )
            }
        })
        if (this.list[2].visible) {
            registerStatistics().then(res => {
                if (res.data.value === 200) {
                    this.list[2].data[0] = res.data.data.currentMonthCount
                    this.list[2].data[1] = res.data.data.totalCount
                    this.list[2].data[2] = res.data.data.auditPassCount
                    this.list[2].data[3] = res.data.data.auditNotPassCount
                }
            })
        }
    }
}
